package zym.diandian.module.sys;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.BatteryManager;

import zym.diandian.tools.BatteryInfo;

public class BatteryBroadcastRec extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        //LogTool.log("battery receiver ");
        String action = intent.getAction();
        if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
            //battery status
            int status = intent.getIntExtra("status", 0);
            switch (status) {
                case BatteryManager.BATTERY_STATUS_UNKNOWN:
                    BatteryInfo.setZt("未知状态");
                    break;
                case BatteryManager.BATTERY_STATUS_CHARGING:
                    BatteryInfo.setZt("充电中");
                    break;
                case BatteryManager.BATTERY_STATUS_DISCHARGING:
                    BatteryInfo.setZt("放电中");
                    break;
                case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
                    BatteryInfo.setZt("未充电");
                    break;
                case BatteryManager.BATTERY_STATUS_FULL:
                    BatteryInfo.setZt("已充满");
                    break;
                default:
                    break;
            }
            //battry health
            int health = intent.getIntExtra("health", 0);
            switch (health) {
                case BatteryManager.BATTERY_HEALTH_UNKNOWN:
                    BatteryInfo.setJk("未知状态");
                    break;
                case BatteryManager.BATTERY_HEALTH_GOOD:
                    BatteryInfo.setJk("健康");
                    break;
                case BatteryManager.BATTERY_HEALTH_OVERHEAT:
                    BatteryInfo.setJk("过热");
                    break;
                case BatteryManager.BATTERY_HEALTH_DEAD:
                    BatteryInfo.setJk("损坏");
                    break;
                case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
                    BatteryInfo.setJk("电压过大");
                    break;
                case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
                    BatteryInfo.setJk("正常");
                    break;
                case BatteryManager.BATTERY_HEALTH_COLD:
                    BatteryInfo.setJk("BATTERY_HEALTH_COLD");
                    break;
                default:
                    break;
            }

            int level = intent.getIntExtra("level", 0);
            int scale = intent.getIntExtra("scale", 0);
            //current power
            BatteryInfo.setDl(((level * 100) / scale) + "%");
            //charge type
            int plugged = intent.getIntExtra("plugged", 0);
            switch (plugged) {
                case BatteryManager.BATTERY_PLUGGED_AC:
                    BatteryInfo.setCd("AC充电器");
                    break;
                case BatteryManager.BATTERY_PLUGGED_USB:
                    BatteryInfo.setCd("USB充电");
                    break;
                case BatteryManager.BATTERY_PLUGGED_WIRELESS:
                    BatteryInfo.setCd("无线充电");
                    break;

                default:
                    break;
            }
            int voltage = intent.getIntExtra("voltage", 0);
            BatteryInfo.setDy("" + (voltage / 1000f) + " V");

            int temperature = intent.getIntExtra("temperature", 0);
            BatteryInfo.setWd("" + (temperature / 10f) + "℃");

            BatteryInfo.setLx("" + intent.getStringExtra("technology"));
        }
    }

}
